<%@page import="entity.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<link rel="stylesheet" type="text/css" href="<%=path %>/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/css/animate.css">
<link rel="stylesheet" href="<%=path %>/css/normalize.css">
<style>
.webdesc { display:inline-block;height:120px;width:100%;word-wrap:break-word; }
.app_footer { background:#111;font-size:13px;color:#555;padding-top:14px;padding-bottom:20px;border-top:1px solid #303030; }
</style>
</head>
<body style="background: #F2F2F2">
<header style="background-image:url('<%=path %>/images/head_pic.jpg');background-size:100% 100%;;" >
	<div class="jumbotron" style="background:rgba(0,0,0,0) !important">
		<div class="container">
			<div class="jumbotron" style="background:rgba(0,0,0,0) !important">
				<div class="text-center" style="color:#fff;letter-spacing:6px;">
					<h1>欢迎下载正版软件！</h1>
				</div>
			</div>
		</div>
	</div>
</header>
<article id="article" class="center-block" style="max-width:1200px;">

<div class="container-fluid">
	<div class="row" id="apps_content">
	</div>
</div>

</article>

<footer>
	<div class="app_footer text-center"></div>
</footer>


<script type="text/javascript" src="<%=path%>/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="<%=path%>/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(function() {

var workspace = function() {
	var downloads;
	
	// 列出应用
	var initDownloads = function() {
		var template = "<div class='col-sm-6 col-md-4'>" +
			"<div class='thumbnail animated fadeInDown'>" +
			"<img src='#picUrl#' class='img-rounded' style='height:185px' />" +
			"<div class='caption'>" +
			"<h3>#appName#</h3>" +
			"<div class='webdesc'><p>#desc#</p></div>" +
			"<p>" +
			"<lable for='downloadUrl'>系统架构：</lable>" +
			"<select name='downloadUrl' id='#appName#'>" +
			"<option value='#inner32#'>校内32</option>" +
			"<option value='#inner64#'>校内64</option>" +
			"<option value='#outer32#'>校外32</option>" +
			"<option value='#outer64#'>校外64</option>" +
			"</select>" +
			"" +
			"<a href='javascript:;' class='btn btn-primary pull-right' name='doDownload' data-appname='#appName#'>下载</a>" +
			"</div></div></div>";

		$.ajax({
			url: "<%=path %>/servlet/soft/QueryDownloadsServlet",
			type: "get",
			dataType: "json",
			async: false,
			success: function(data) {
				if("1" === data["retCode"]) {
					downloads = data["downloads"];
				} else {
					downloads = [];
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				downloads = [];
				alert("QueryDownloadsServlet:" + XMLHttpRequest.status + ":" + XMLHttpRequest.readyState+ ":" + textStatus);
			}
		});
		
		var html = "";
		downloads.forEach(function(download) {
			var thisT = template;
			thisT = thisT.replace(/#picUrl#/g,download["appPicURL"]).replace(/#appName#/g, download["appName"]).replace(/#desc#/g, download["webDesc"])
				.replace(/#inner32#/g, download["inner32"]).replace(/#inner64#/g, download["inner64"]).replace(/#outer32#/g, download["outer32"]).replace(/#outer64#/g, download["outer64"]);
			html += thisT;
		});
		
		$("#apps_content").html(html);
		
		downloadSoft();
	}
	
	// 下载
	var downloadSoft = function() {
		$("[name='doDownload']").each(function(){
			var appName = $(this).data("appname");
			$(this).click(function() {
				if("" === $("#" + appName).val()) {
					swal("sorry", "下载地址不存在", "error");
				} else {
					$(this).attr({"href":$("#" + appName).val()});
				}
			});
		});
	}
	
	return {
		initDownloads: initDownloads
	}
}();

workspace.initDownloads();
});
</script>
</body>
</html>